package com.JinYuan;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.realm.text.IniRealm;
import org.apache.shiro.subject.Subject;
import org.junit.Test;

/**
 * @author 金园
 * @create 2022/5/12
 * @Description
 * @className Demo
 * @packageName com.JinYuan
 */
public class Demo {
    @Test
    public void testshiro(){
        /*//安全管理器，核心控制器shiro大脑
        DefaultSecurityManager securityManager = new DefaultSecurityManager();
        IniRealm realm = new IniRealm("classpath:shiro.ini");
        //realm：提供用户和账号信息 （存储在服务器）
        securityManager.setRealm(realm);
        //设置安全管理对象
        SecurityUtils.setSecurityManager(securityManager);
        //一切对外接口
        Subject subject = SecurityUtils.getSubject();
        //有用户输入账号密码，和服务器中的做对比
        UsernamePasswordToken token = new UsernamePasswordToken("zhangsan","123456");
        //登录
        subject.login(token);
        //退出登录
        subject.logout();
        //验证
        System.out.println("是否通过认证" + subject.isAuthenticated());*/
        

        //安全管理器
        DefaultSecurityManager securityManager = new DefaultSecurityManager();
        IniRealm realm = new IniRealm("classpath:shiro.ini");
        //提供用户和账户信息
        securityManager.setRealm(realm);
        //设置安全管理对象
        SecurityUtils.setSecurityManager(securityManager);
        //一切对外接口
        Subject subject = SecurityUtils.getSubject();
        //用户输入账户和密码与服务器对比
        UsernamePasswordToken token = new UsernamePasswordToken("zhangsan","123456");
        //登录
        subject.login(token);
        //退出登录

        //判断是否成功
        System.out.println(subject.isAuthenticated());













    }

}
